<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:include="admin/head :: head" th:with="title=菜单添加">
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" action="" lay-filter="formfilter">
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>菜单名称:</label>
                <div class="layui-input-block">
                    <input type="text" name="name"  lay-verify="required|name" autocomplete="off" placeholder="菜单名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">父菜单:</label>
                <div class="layui-input-block">
                    <select class="select" id="parentId" name="parentId">
                        <option value=""></option>
                        <option th:each="menu,menuState:${menus}" th:value="${menu.id}" th:text="${menu.name}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">连接地址:</label>
                <div class="layui-input-block">
                    <input type="text" name="url"  autocomplete="off" placeholder="连接地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>位置:</label>
                <div class="layui-input-block">
                    <input type="text" name="position"  lay-verify="required|position" autocomplete="off" placeholder="位置" class="layui-input" value="10">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="formSubmit">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>


        layui.use(['layedit', 'layer', 'jquery','liuQi'], function () {
            var form = layui.form,
                    liuQi = layui.liuQi,
                    laydate = layui.laydate;

            form.render();

            //自定义验证规则
            form.verify({
                url: function (value) {
                },
                name: function (value) {
                },
                position: function (value) {
                },
            });
            //监听提交
            form.on('submit(formSubmit)', function (data) {
                data=data.field;
                liuQi.ajax("/admin/menu/add",data,
                        function (data) {
                            //关闭
                            parent.layer.msg(data.msg);
                            parent.layui.table.reload('currentTableId');
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                );
                return false;
            });
        });
</script>

</body>
</html>